let data = {
    pagenum:1,
    pagesize:2,
}

let t;

function renderEasyList() {
    $.ajax({
        url:'/my/article/list',
        data:data,
        success:function (res) {
            
            t = res.total;
            let str = '';
            res.data.forEach(item => {
                str += `
                <tr>
                <td>${item.title}</td>
                <td>${item.cate_name}</td>
                <td>${item.pub_date}</td>
                <td>${item.state}</td>
                <td>
                    <button style="width: 64px; height: 38px;" type="button" class="layui-btn layui-btn-xs">修改</button>
                    <button style="width: 64px; height: 38px;" type="button" class="layui-btn layui-btn-danger layui-btn-xs">删除</button>
                </td>
            </tr>`
            });
            $('tbody').html(str);
            showPage(t)
        }
    })
}

function showPage(t) {
    let laypage = layui.laypage;
    laypage.render({
        elem:'page',
        count:t,
        curr:data.pagenum,
        limit:data.pagesize,
        limits:[2,3,5,10],
        layout:['count', 'limit', 'prev', 'page', 'next', 'skip'],
        jump:function (obj, first) {
            if (!first) {
                data.pagenum = obj.curr;
                data.pagesize = obj.limit;
                renderEasyList()
            }
        }
    })
}

$.ajax({
    url:'/my/article/list',
    data:data,
    success:function (res) {
        console.log(res);
        let strfir = '';
        let strsec = '';
        res.data.forEach(item => {
            strfir += `<option value="010">${item.title}</option>`
            strsec += `<option value="010">${item.state}</option>`
        });
        $('#easyName').append(strfir);
        $('#easyCate').append(strsec)
    }
})

renderEasyList()
showPage(t)                    